package com.woniuxy.store.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.food.client.foodtypeclient.FoodTypeManageClient;
import com.woniuxy.food.client.foodtypeclient.FoodTypeQueryClient;
import com.woniuxy.food.client.param.InsertFoodTypeParam;
import com.woniuxy.food.client.param.SearchFoodTypeByConditionParam;
import com.woniuxy.food.client.param.UpdateFoodTypeParam;
import com.woniuxy.food.client.param.UpdateFoodTypeStateParam;
import com.woniuxy.food.client.result.FoodTypeClientDto;
import com.woniuxy.store.app.util.StoreIdUtil;
import com.woniuxy.store.client.FoodTypeClient;
import com.woniuxy.store.client.param.foodParam.InsertFoodTypeParams;
import com.woniuxy.store.client.param.foodParam.SearchFoodTypeByConditionParams;
import com.woniuxy.store.client.param.foodParam.UpdateFoodTypeParams;
import com.woniuxy.store.client.param.foodParam.UpdateFoodTypeStateParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/store/food")
public class FoodTypeClientImpl implements FoodTypeClient {

    @Autowired
    private FoodTypeManageClient foodTypeManageClient;
    @Autowired
    private FoodTypeQueryClient foodTypeQueryClient;

    @Override
    @Log("开始添加食品类型")
    public Result insertFoodType(@Valid InsertFoodTypeParams var1) {
        InsertFoodTypeParam param = BeanUtil.toBean(var1,InsertFoodTypeParam.class);
        param.setStoreId(StoreIdUtil.getFromToken());
        return foodTypeManageClient.insertFoodType(param);
    }

    @Override
    @Log("批量上下架食品类型")
    public Result updateFoodTypeByIds(@Valid UpdateFoodTypeStateParams var1) {
        UpdateFoodTypeStateParam param = BeanUtil.toBean(var1, UpdateFoodTypeStateParam.class);
        param.setStoreId(StoreIdUtil.getFromToken());
        return foodTypeManageClient.updateFoodTypeByIds(param);
    }

    @Override
    @Log("修改食品类型信息")
    public Result updateFoodTypeById(@Valid UpdateFoodTypeParams var1) {
        UpdateFoodTypeParam param = BeanUtil.toBean(var1, UpdateFoodTypeParam.class);
        param.setStoreId(StoreIdUtil.getFromToken());
        return foodTypeManageClient.updateFoodTypeById(param);
    }

    @Override
    @Log("删除食品类型信息")
    public Result deleteFoodTypeByIds(Integer[] var1) {
        Integer storeId = StoreIdUtil.getFromToken();
        return foodTypeManageClient.deleteFoodTypeByIds(var1,storeId);
    }

    @Override
    @Log("根据条件查询食品类型")
    public Result searchFoodTypeByCondition(@Valid SearchFoodTypeByConditionParams param) {
        SearchFoodTypeByConditionParam searchFoodTypeByConditionParam = BeanUtil.toBean(param, SearchFoodTypeByConditionParam.class);
        searchFoodTypeByConditionParam.setStoreId(StoreIdUtil.getFromToken());
        return foodTypeQueryClient.searchFoodTypeByCondition(searchFoodTypeByConditionParam);
    }
}
